'''
模拟游戏过程 N2N
'''
# -*- coding:utf-8 -*-
class Solution:
    def LastRemaining_Solution(self, n, m):
        # write code here
        if n < 1:
            return -1
        players = [i for i in range(n)]
        final = -1
        beginner = 0
        while players:
            # 取余
            singer = (beginner + m - 1) % n
            winner = players.pop(singer)
            n -= 1
            # 从上个singer的位置出发
            beginner = singer
        return winner
'''
递归 N N
'''
# -*- coding:utf-8 -*-
class Solution:
    def LastRemaining_Solution(self, n, m):
        # write code here
        x = 0
        if n == 0:
            return -1
        for i in range(2,n+1):
            x = (x + m) % i
        return x
a = [i for i in range(10)]
print(a)
'''
迭代
'''
